<?php
require_once 'init_app.php'; 

set_time_limit(0);

/*$suppliers = ORM::factory('supplier')
                ->find_all()
                ->as_array();
foreach ($suppliers as $supplier) {
    try {
        DB::insert('supplier_stats', array('supplier_id'))
                            ->values(array($supplier->id))->execute(); 
    } catch (Database_Exception $e) {
        if (strstr($e->getMessage(), 'Duplicate entry') !== false) {
            continue;
        }
        die($e->getMessage());
    }
}  */

$goods = ORM::factory('good')
                ->offset(10000)
                ->limit(40000)
                ->find_all()
                ->as_array();
foreach ($goods as $good) {
    try {
        DB::insert('good_stats', array('good_id'))
                            ->values(array($good->id))->execute(); 
    } catch (Database_Exception $e) {
        if (strstr($e->getMessage(), 'Duplicate entry') !== false) {
            continue;
        }
        die($e->getMessage());
    }
}

echo 'ok';